package top.xiaoshuaila.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.xiaoshuaila.pojo.Joblevel;
import top.xiaoshuaila.pojo.Position;
import top.xiaoshuaila.pojo.RespBean;
import top.xiaoshuaila.service.IJoblevelService;
import top.xiaoshuaila.service.IPositionService;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小帅啦
 * @since 2021-05-01
 */
@RestController
@RequestMapping("/system/basic/joblevel")
@Api(tags = "职称管理")
public class JoblevelController {
    @Autowired
    private IJoblevelService joblevelService;
    @ApiOperation("获取所有职称信息")
    @GetMapping("/")
    private List<Joblevel> getAllPositions(){
        return joblevelService.list();
    }

    @ApiOperation("添加职称")
    @PostMapping("/")
    private RespBean addPositions(@RequestBody Joblevel joblevel){
        joblevel.setCreateDate(LocalDateTime.now());
        if(joblevelService.save(joblevel))
            return RespBean.success("添加成功!");
        return RespBean.error("添加失败!");
    }

    @ApiOperation("更新职称")
    @PutMapping("/")
    private RespBean updatePositions(@RequestBody Joblevel joblevel){
        if(joblevelService.updateById(joblevel))
            return RespBean.success("更新成功!");
        return RespBean.error("更新失败!");
    }

    @ApiOperation("删除职称")
    @DeleteMapping("/{id}")
    private RespBean deletePositions(@PathVariable Integer id){
        if(joblevelService.removeById(id))
            return RespBean.success("删除成功!");
        return RespBean.error("删除失败!");
    }

    @ApiOperation("批量删除职位")
    @DeleteMapping("/")
    private RespBean deletePositions(Integer[]ids){
        if(joblevelService.removeByIds(Arrays.asList(ids)))
            return RespBean.success("删除成功!");
        return RespBean.error("删除失败!");
    }
}
